threads: Do not release the GDK lock if it hasn't been acquired yet
authorEmmanuele Bassi <ebassi@gnome.org>
Tue, 26 Aug 2014 11:15:06 +0000 (12:15 +0100)
committerMatthias Clasen <mclasen@redhat.com>
Wed, 27 Aug 2014 00:07:33 +0000 (20:07 -0400)
commit79c3ff3c4ed74bbcc820dac2d5180fa4d48d55ec
tree0f712591a3119b03968eb4a1ae1e650e60178c52
parent0f0fc59fbda5d037d50c599c018bca9befef6ad1
threads: Do not release the GDK lock if it hasn't been acquired yet

Since GLib ≥ 2.41, attempting to release an unlocked mutex will abort(),
as it happens on most systems already.

Given the lack of proper documentation on how to use GDK with threads,
there is code in the wild that does:

    gdk_threads_init ();
    gdk_init ();

    ...

    gtk_main ();

instead of the idiomatically correct:

    gdk_threads_init ();
    gdk_threads_enter ();

    gtk_init ();

    ...

    gtk_main ();

    ...

    gdk_threads_leave ();

Which means that gtk_main() will try to release the GDK lock, and thus
trigger an error from GLib.

we cannot really fix all the wrong code everywhere, and since it does
not cost us anything, we can work around the issue inside GDK itself, by
trying to acquire the GDK lock inside gdk_threads_leave() with
trylock().

https://bugzilla.gnome.org/show_bug.cgi?id=735428
gdk/gdk.c